package exc;

import java.util.Scanner;

public class BubbleSort extends TestAbstract{
	// Random r = new Random();
	Scanner sc = new Scanner(System.in);
	int[] sort = new int[5];
	String s = null;
	String[] ss = null;
	// int temp = 0;
	public static void main(String[] args) {
		BubbleSort rs = new BubbleSort();
		// get String of number from console by customer input
		rs.getNumber();
		// spilt the number String to number
		rs.numberToArray();
		// bubble sort
		rs.sort();
		// print the sort record
		rs.printRecord();
		
		// test abstract class can have constructor,non abstract method can implement
		rs.printTest();
	}

	private void getNumber() {
		System.out.println("please input 5 numbers and among them insert ‘，’：");
		s = sc.nextLine();
	}
	
	private void numberToArray() {
		ss = s.split(",");
		for (int i = 0; i < sort.length; i++) {
			// sort[i] = r.nextInt(100);
			try {
				sort[i] = Integer.parseInt(ss[i]);
			} catch (NumberFormatException e) {
				System.out.print("must input number!");
				return;
			}
		}
	}
	
	private void sort() {
		// bubble sort
		for (int i = 0; i < sort.length; i++) {
			for (int j = 0; j < sort.length; j++) {
				if (sort[i] < sort[j]) {
					// temp = sort[j];
					// sort[j] = sort[i];
					// sort[i] = temp;
					// hav't third variable to exchange the value of sort[i] and
					// sort[j]
					sort[i] = sort[i] + sort[j];
					sort[j] = sort[i] - sort[j];
					sort[i] = sort[i] - sort[j];
				}
				System.out.print(sort[j] + " ");
			}
			System.out.println();
		}
	}

	public void printRecord() {
		for (int i = 0; i < sort.length; i++) {
			System.out.print(sort[i] + " ");
		}
	}
}
